Load Data

brewing_materials <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-31/brewing_materials.csv')
beer_taxed <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-31/beer_taxed.csv')
brewer_size <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-31/brewer_size.csv')
beer_states <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-31/beer_states.csv')

head(brewing_materials)
## # A tibble: 6 x 9
##   data_type material_type  year month type  month_current month_prior_year
##   <chr>     <chr>         <dbl> <dbl> <chr>         <dbl>            <dbl>
## 1 Pounds o… Grain Produc…  2008     1 Malt…     374165152        365300134
## 2 Pounds o… Grain Produc…  2008     1 Corn…      57563519         41647092
## 3 Pounds o… Grain Produc…  2008     1 Rice…      72402143         81050102
## 4 Pounds o… Grain Produc…  2008     1 Barl…       3800844          2362162
## 5 Pounds o… Grain Produc…  2008     1 Whea…       1177186          1195381
## 6 Pounds o… Total Grain …  2008     1 Tota…     509108844        491554871
## # … with 2 more variables: ytd_current <dbl>, ytd_prior_year <dbl>
head(beer_taxed)
## # A tibble: 6 x 10
##   data_type tax_status  year month type  month_current month_prior_year
##   <chr>     <chr>      <dbl> <dbl> <chr>         <dbl>            <dbl>
## 1 Barrels … Totals      2008     1 Prod…      16211480         15880125
## 2 Barrels … Taxable     2008     1 In b…      13222104         12824278
## 3 Barrels … Taxable     2008     1 In b…       1371239          1357372
## 4 Barrels … Taxable     2008     1 Tax …          7426             8419
## 5 Barrels … Sub Total…  2008     1 Sub …      14600769         14190069
## 6 Barrels … Tax Free    2008     1 For …        262985           268473
## # … with 3 more variables: ytd_current <dbl>, ytd_prior_year <dbl>,
## #   tax_rate <chr>
head(brewer_size)
## # A tibble: 6 x 6
##    year brewer_size    n_of_brewers total_barrels taxable_removals total_shipped
##   <dbl> <chr>                 <dbl>         <dbl>            <dbl>         <dbl>
## 1  2009 6,000,001 Bar…           18    171232882.       159643984.       3639970
## 2  2009 1,000,001 to …            4      9970404.         9592723.         14548
## 3  2009 500,001 to 1,…            7      4831386.         4535659.         21563
## 4  2009 100,001 to 50…           27      5422156.         4469289.        128000
## 5  2009 60,001 to 100…           19      1501977.         1224618.         95732
## 6  2009 30,001 to 60,…           32      1412245.         1233959.         14369
head(beer_states)
## # A tibble: 6 x 4
##   state  year barrels type       
##   <chr> <dbl>   <dbl> <chr>      
## 1 AK     2008   2068. On Premises
## 2 AK     2009   2264. On Premises
## 3 AK     2010   1929. On Premises
## 4 AK     2011   2251. On Premises
## 5 AK     2012   2312. On Premises
## 6 AK     2013   2156. On Premises

Data Manipulation

beer_states %>% #only viewing barrels in New Jersey
  filter(state == "NJ") -> nj_beer

head(nj_beer) #view dataframe
## # A tibble: 6 x 4
##   state  year barrels type       
##   <chr> <dbl>   <dbl> <chr>      
## 1 NJ     2008   4958. On Premises
## 2 NJ     2009   4945. On Premises
## 3 NJ     2010   5642. On Premises
## 4 NJ     2011   5500. On Premises
## 5 NJ     2012   5385. On Premises
## 6 NJ     2013   5536. On Premises

Data Visualization

hchart(nj_beer, "line", hcaes(x = year, y = barrels, group = type)) %>%
  hc_title(text = "Production of Beer Barrels in New Jersey") -> plot_beer
## Warning: `parse_quosure()` is deprecated as of rlang 0.2.0.
## Please use `parse_quo()` instead.
## This warning is displayed once per session.
plot_beer

This TidyTuesday was lot of fun to make, especially since it was interactive. The highcharter website had plenty of examples that made it quite easy to learn. I was actually expecting it to be more complex, but it was quite similar to plotting in ggplot. It made me realize that once you know the foundation, you use that as a base to learn new concepts.

nj_beer %>%
  mutate(year = as.character(year)) %>%
  ggplot(aes(x = year, y = barrels, group = type, color = type)) +
  geom_point() + geom_line() + 
  ggtitle("Production of Beer Barrels in New Jersey") +
  labs(x = "Year", y = "Barrels", color = "Type") +
  theme_classic() +
  theme(legend.position = "bottom")-> p2

ggplotly(p2)
ggsave("nj_beer.png", plot = p2)
## Saving 7.6 x 4 in image

An alternative to highcharter is plotly. It is more straight forward than highcharter, especially if you are already familiar with ggplot. It is also more interactive than highcharter. Nonetheless, both are options for interactive data figures.